<?php      
/*******跳转模板*******/     
global $wp_rewrite,$wp_query;      
//从请求的地址中获取文章ID      
if( isset($wp_query->query_vars['pid']) && $wp_query->query_vars['pid']!='' )      
    $post_id = $wp_query->query_vars['pid'];      
else     
    $post_id = 0;      
     
//如果文章ID存在      
if( $post_id ){      
    //通过文章ID获取要跳转的站外链接--自定义字段      
    $buy_link = get_post_meta($post_id,'_buy_link',true);   
    $buy_link = htmlspecialchars_decode($buy_link);//将html实体换回预定义字符   
    $buy_link = trim($buy_link);   
    $buy_link = addhttp(trim($buy_link));   
    if($buy_link){ ?>      
        <?php //跳转到对应的链接?>      
        <script type="text/javascript">window.location.href="<?php echo $buy_link;?>";</script>      
    <?php }else{ ?>      
        <?php //如果没有设置跳转到奥首页?>      
        <script type="text/javascript">window.location.href="<?php echo home_url();?>";</script>      
    <?php }      
}else{ ?>      
<?php //无ID则跳转到首页 ?>      
    <script type="text/javascript">window.location.href="<?php echo home_url();?>";</script>      
<?php } ?>   